# -*- coding: utf-8 -*-
from django.shortcuts import get_object_or_404
from django import forms
from django.forms import ModelForm, Textarea
from django.forms.widgets import HiddenInput
from django.forms.extras import SelectDateWidget
from poudres.models import Commande, Client, Poudre, Event, Type_Event, Fournisseur

class EventForm(ModelForm):
    poudre = forms.ModelChoiceField(label=(u"Tên bột"), queryset=Poudre.objects.all(), widget=forms.widgets.HiddenInput(),required = True)
    TE = forms.ModelChoiceField(label=(u"Thao tác"), queryset=Type_Event.objects.all(),required = True)

    quantite = forms.FloatField(label=(u"Số lượng"),required = True)
    prix = forms.FloatField(label=(u"Giá"),required = True)
    somme = forms.FloatField(label=(u"Tổng tiền"),widget=forms.widgets.HiddenInput())
    commande = forms.ModelChoiceField(label=(u"Đơn hàng"), queryset=Commande.objects.all(),required = True)
    commentaires = forms.CharField(widget=Textarea(attrs={'rows':4, 'cols':19}), required = False, label=(u"Ghi chú"))
    instock = forms.FloatField(label=(u"Tồn kho"),widget=forms.widgets.HiddenInput(),required = True)
    class Meta:
        model= Event
     
class PoudreForm(ModelForm):
    nom = forms.CharField(required = True,label=(u"Tên bột"))
    codeP = forms.CharField(required = True,label=(u"Mã bột"))
    fournisseur = forms.ModelChoiceField(queryset=Fournisseur.objects.all(),label=(u"Nhà cung cấp"),required = True) 
    instock = forms.FloatField(initial=0,required = False,label=(u"Tồn kho"))
    commentaires = forms.CharField(widget=Textarea(attrs={'rows':4, 'cols':20}), required = False, label=(u"Ghi chú"))
    class Meta:
        model= Poudre

class CommandeForm(ModelForm):
    nom = forms.CharField(label=(u"Tên đơn hàng"),required = True)
    client = forms.ModelChoiceField(queryset=Client.objects.all(),label=(u"Khách hàng"),required = True)
    date_livraison = forms.DateTimeField(label=(u"Ngày giao hàng"))
    date_facturation = forms.DateTimeField(label=(u"Ngày xuất hóa đơn"))
    date_paiement = forms.DateTimeField(label=(u"Ngày thanh toán"))
    quantite = forms.FloatField(label=(u"Số lượng"), required=True)
    unite = forms.CharField(label=(u"Đơn vị"),required=True)
    prix = forms.FloatField(label=(u"Giá tiền"), required=True)
    autre1 = forms.FloatField(label=(u"Dịch vụ khác"), required=False)
    autre2 = forms.FloatField(label=(u"Dịch vụ khác"), required=False)
    autre3 = forms.FloatField(label=(u"Dịch vụ khác"), required=False)
    total = forms.FloatField(label=(u"Dịch vụ khác"), required=False)
    etat = forms.BooleanField(label=(u"Trạng thái"),required=False)
    commentaires = forms.CharField(widget=Textarea(attrs={'rows':4, 'cols':20}), required = False, label=(u"Ghi chú"))
    class Meta:
        model= Commande